<template>
  <div class="swiper-container" ref="myswiper">
    <div class="swiper-wrapper">
      <slot></slot>
    </div>
    <!-- Add Pagination -->
    <div class="swiper-button-next" v-if="navigation"></div>
    <div class="swiper-button-prev" v-if="navigation"></div>
    <div class="swiper-pagination"></div>
  </div>
</template>

<script>
// 导入Swiper
import Swiper from "@/assets/swiper/swiper.min.js";
// 导入css
import "@/assets/swiper/swiper.min.css";
export default {
  props: {
    slidesPerView: { type: Number, default: 1 },
    navigation: { type: Boolean, default: true },
  },
  // 组件渲染完毕后导入
  mounted() {
    var that = this;
    // 初始化swiper
    var swiper = new Swiper(this.$refs.myswiper, {
      keyboard: true,
      slidesPerView: that.slidesPerView,
      loop: true,
      pagination: {
        el: ".swiper-pagination",
        clickable: true,
      },
      navigation: {
        nextEl: ".swiper-button-next",
        prevEl: ".swiper-button-prev",
      },
    });
  },
};
</script>

<style>
:root {
  --swiper-theme-color: #e30000;
}
.swiper-container {
  width: 100%;
  height: 100%;
  margin-left: auto;
  margin-right: auto;
}

.swiper-slide {
  text-align: center;
  font-size: 18px;
  background: #fff;

  /* Center slide text vertically */
  display: -webkit-box;
  display: -ms-flexbox;
  display: -webkit-flex;
  display: flex;
  -webkit-box-pack: center;
  -ms-flex-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  -webkit-box-align: center;
  -ms-flex-align: center;
  -webkit-align-items: center;
  align-items: center;
}
</style>
